package com.example.aopdemo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-01-26
 * Time: 18:48
 */
@Slf4j
@Component
@Aspect
public class TimeRecordAspect {
    //@Around("execution(* com.example.aopdemo.controller.*.*(..))")
    //@Around("com.example.aopdemo.aspect.AspectDemo.pt()")
    //@Around("@annotation(com.example.aopdemo.aspect.TimeRecord)")
    @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public Object timeRecord(ProceedingJoinPoint pjt) {
        log.info("TimeRecordAspect执行前...");
        long start = System.currentTimeMillis();
        Object o = null;
        try {
            o = pjt.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
        log.info("TimeRecordAspect执行后...");
        log.info(pjt.getSignature() + "耗时" + (System.currentTimeMillis() - start) + "ms");
        return o;
    }
}
